/*
 * MatrixPositionComparator.h
 *
 *  Created on: Oct 9, 2012
 *      Author: lfelipe
 */

#ifndef MATRIXPOSITIONCOMPARATOR_H_
#define MATRIXPOSITIONCOMPARATOR_H_

#include "LayerComparator.h"

class MatrixPositionComparator: public LayerComparator
{
public:
    MatrixPositionComparator(){}
    virtual ~MatrixPositionComparator(){}

    virtual double compare( Layer & a,  Layer & b)
    {
        double distance =0;
    //    std::vector<short int> fixed_cells = std::vector<short int>(a.number_of_cells());
        for (int i = 0; i < a.grid_size_x(); ++i) {
            for (int j = 0; j < a.grid_size_y(); ++j) {
                Cell * a_cell = a.get_cell_at_position(i,j);
                Cell *b_cell = b.get_cell_at_position(i,j);
                if( a_cell != NULL)
                {
                    if(b_cell != NULL) {
                        if(a_cell->cell_id() != b_cell->cell_id()) {
                            distance++;
                        }
                    } else {
                        distance++;
                    }
                }
            }
        }
        return (distance==0)?0:(distance/(a.grid_size_x()*a.grid_size_y()));
    }

};

#endif /* MATRIXPOSITIONCOMPARATOR_H_ */
